home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Leser 15
/
Amiga Plus Leser CD 15.iso
/
Tools
/
Development
/
PluginSRC_EvenMore
/
generic2text4.e
< prev
next >
Wrap
Text File
|
2002-03-12
|
4KB
|
196 lines
/*
Generic2Text
EvenMore FileIO plugin
Author: Chris Perver
Copyright (c) 2001
*/
OPT REG=5
LIBRARY 'generic2text.plugin',1,1,'Generic2Text 1.02' IS em_main, em_end, em_info, em_pluginid, em_begin, em_format
MODULE 'tools/ctype', '*epo'
DEF memadr:PTR TO CHAR, mem2:PTR TO CHAR, lenadr, len2
PROC em_isdatatype(memadr, l)
DEF c = 0, loop = TRUE, isgen = FALSE
DEF end
-> FIRST AND LAST BYTES FOR BINARY CHARS
c := 0
end := Min(8, l)
WHILE loop AND (c < end)
SELECT 256 OF memadr[c]
CASE "\t", "\e"
INC c
CASE " " TO $7e
INC c
CASE "\n", "\b"
INC c
DEFAULT
isgen := TRUE
loop := FALSE
ENDSELECT
ENDWHILE
IF isgen = FALSE
c := Max(0, l - 8)
end := l
WHILE loop AND (c < end)
SELECT 256 OF memadr[c]
CASE "\t", "\e"
INC c
CASE " " TO $7e
INC c
CASE "\n", "\b"
INC c
DEFAULT
isgen := TRUE
loop := FALSE
ENDSELECT
ENDWHILE
ENDIF
ENDPROC isgen
PROC em_parsedata(epo:PTR TO em_pluginobj)
DEF count = 0, count2 = 0
DEF loop = TRUE
DEF a
->mem2 := memadr
memadr := epo.buffer
lenadr := epo.length
mem2 := epo.nbuffer
-> SKIP UNTIL WE GOT SOME TEXT
WHILE (count < lenadr)
EXIT (memadr[count] = "\n") OR (memadr[count] = "\b")
INC count
ENDWHILE
WHILE loop AND (count < lenadr)
SELECT 256 OF memadr[count]
CASE "\b", "\n"
-> FIND START OF LINE
a := count
WHILE ((memadr[a-1] >= " ") AND (memadr[a-1] <= $7e) AND (a > 0)) DO DEC a
-> IF ITS NOT A STRAY LF/CR
IF (a < count) OR ((memadr[a-1] = "\n") OR (memadr[a-1] = "\b"))
-> DEC count
count2 := copyline(memadr, a, count -1, mem2, count2)
loop := FALSE
ENDIF
ENDSELECT
IF loop THEN INC count
ENDWHILE
loop := TRUE
WHILE (count < lenadr)
SELECT 256 OF memadr[count]
CASE "\b", "\n"
-> FIND START OF LINE
a := count
WHILE (((memadr[a+1] >= " ") AND (memadr[a+1] <= $7e) OR (memadr[a+1] = "\t")) AND (a < lenadr)) DO INC a
-> IF ITS NOT A STRAY LF/CR
IF (a > count) OR ((memadr[a+1] = "\n") OR (memadr[a+1] = "\b"))-> OR (memadr[a+1] = "\t"))
count2 := copyline(memadr, count, a, mem2, count2)
ENDIF
count := a
ENDSELECT
INC count
ENDWHILE
mem2[count2] := "\n"
ENDPROC mem2, count2
-><
PROC copyline(mem:PTR TO CHAR, pos, end, m2:PTR TO CHAR, pos2)
-> DEF loop = TRUE
DEF currchar = 0, oldcc, oldpos, wordwrap = 80
WHILE (pos <= end)
SELECT 256 OF mem[pos]
CASE "\n", "\b", "\t"
m2[pos2++] := mem[pos++]
currchar := 0
CASE " " TO $7e
m2[pos2] := mem[pos++]
INC currchar
IF FALSE ->IF ww = TRUE
IF currchar >= wordwrap
-> Find last space
IF isspace(m2[pos2]) = TRUE
m2[pos2++] := "\n"
currchar := 0
ELSE
oldpos := pos2
oldcc := currchar
WHILE isspace(m2[pos2]) = FALSE
m2[pos2 + 1] := m2[pos2]
DEC pos2
DEC currchar
ENDWHILE
INC pos2
m2[pos2] := "\n"
currchar := oldcc - currchar
pos2 := oldpos + 1
ENDIF
ENDIF
ENDIF
INC pos2
ENDSELECT
EXIT (pos > end)
ENDWHILE
ENDPROC pos2
-> *** STANDARD PROCS FOR PLUGINS
PROC em_main(epo:PTR TO em_pluginobj)
mem2, len2 := em_parsedata(epo)
-> epo.buffer := mem2
-> epo.length := len2
epo.nlength := len2
RETURN TRUE
ENDPROC
PROC em_begin(epo:PTR TO em_pluginobj)
IF em_isdatatype(epo.buffer, epo.length)
RETURN "MEM", (epo.length * 2)
ELSE
RETURN FALSE
ENDIF
ENDPROC
PROC em_end() IS EMPTY
PROC em_info() IS 'Generic2Text 1.02'
PROC em_pluginid() IS "FILE"
PROC em_format() IS 'Generic'
PROC main() IS EMPTY